#ifndef LOGIC_H
#define LOGIC_H

#include <iostream>
#include <string>
#include <vector>
#include <fstream>

#include "Parser.h"
#include "Data.h"
#include "Task.h"
#include "Writer.h"

#include "LogicAdd.h"
#include "LogicDelete.h"
#include "LogicSort.h"
#include "LogicList.h"
#include "LogicEdit.h"
#include "LogicDone.h"
#include "LogicFlag.h"
#include "LogicClear.h"
#include "LogicUndo.h"

#include <boost\date_time.hpp>
#include <stack>

using namespace std;
using namespace boost::posix_time;
using namespace boost::gregorian;

class Logic {
	
public:
	// execution for UI
	string executeUserCommand(string userCommand, vector<Task>& tasksVector);

	Logic();
	~Logic();

private:
	// LOGIC MESSAGE
	static const string INVALID_COMMAND_MESSAGE;

	// FILE NAME
	static const string FILE_NAME;

	// ERROR LOG FILE NAME
	static const string ERROR_LOG_FILE_NAME;
	static const string ERROR_LOG_FILE_EOF;

	Parser* _parser;
	Data* _data;
	Writer* _writer;
	Task _task;
	stack< Data > undoStackData;

	LogicAdd* _logicAdd;
	LogicDelete* _logicDelete;
	LogicSort* _logicSort;
	LogicList* _logicList;
	LogicEdit* _logicEdit;
	LogicDone* _logicDone;
	LogicFlag* _logicFlag;
	LogicClear* _logicClear;
	LogicUndo* _logicUndo;

	// support up to 10 undo
	// 11 writer states (including the main _writer)
	// cycles through the 10 states
	Writer* states[10];

	// setup
	void setupMainWriter();
	void setupData();
	void setupParser();
	void populateData();

	// log error messages
	void logErrors(string errorMessage, int undoState);

	// helper functions
	bool isOutOfBounds(int index, int size);

};

#endif